package com.ticket.sass.admin.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ticket.sass.common.entity.tenant.OrderCommodityEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ywb
 * @since 2024-03-07
 */
public interface OrderCommodityMapper extends BaseMapper<OrderCommodityEntity> {
    
    @Select("""
        SELECT
            o.id AS order_id,
            o.order_no,
            o.pay_price,
            o.pay_status,
            o.pay_time,
            o.pay_type,
            o.use_coupon,
            o.created_at AS order_created_at,
            ot.*
        FROM
            orders o
        LEFT JOIN
            order_commodities ot ON o.id = ot.order_id
         ${ew.customSqlSegment}
        """)
    IPage<OrderCommodityEntity> queryPage(Page<OrderCommodityEntity> page, @Param(Constants.WRAPPER) QueryWrapper<OrderCommodityEntity> queryWrapper);
    
    @Select("""
        SELECT
            o.id AS order_id
        FROM
            orders o
        LEFT JOIN
            order_commodities ot ON o.id = ot.order_id
         ${ew.customSqlSegment}
        """)
    List<Long> orderId(@Param(Constants.WRAPPER) QueryWrapper<OrderCommodityEntity> queryWrapper);
}
